package com.library.controller;

import com.library.entity.Book;
import com.library.service.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/books")
public class BookController {
    
    @Autowired
    private BookService bookService;
    
    @GetMapping
    public List<Book> getAllBooks() {
        return bookService.findAllBooks();
    }
    
    @GetMapping("/{id}")
    public Book getBook(@PathVariable Integer id) {
        return bookService.findBookById(id);
    }
    
    @PostMapping
    public boolean addBook(@RequestBody Book book) {
        return bookService.addBook(book);
    }
    
    @PutMapping("/{id}")
    public boolean updateBook(@PathVariable Integer id, @RequestBody Book book) {
        book.setId(id);
        return bookService.updateBook(book);
    }
    
    @DeleteMapping("/{id}")
    public boolean deleteBook(@PathVariable Integer id) {
        return bookService.deleteBook(id);
    }
} 